﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace HMS_Hospital_Team2._6.DA
{
    class DichVuDA
    {
        HMSHospitalEntities context = new HMSHospitalEntities();
        PubicLibDA pubDV = new PubicLibDA();
        // load dữ liệu lên gridview
        public DataTable LoadDuLieuDA()
        {
            var Dichvu = from dv in context.DichVus
                         select new
                         {
                             dv.MaNhomDV,
                             dv.MaDichVu,
                             dv.TenDichVu,
                             dv.GiaDichVu,
                             dv.GhiChu,
                             dv.TrangThai
                         };
            return pubDV.LinqToDataTable(Dichvu);
        }

        // load dữ liệu lên combobox
        public DataTable LoadNhomDVDA()
        {
            var TenDV = from tendv in context.NhomDichVus
                        select new
                        {
                            tendv.MaNhomDV,
                            tendv.TenNhomDV
                        };
            return pubDV.LinqToDataTable(TenDV);
        }

        // Tạo mới dịch vụ
        public static void ThemMoiDichvu(string manhomdv, string madichvu, string tendichvu, int igiaDV,
                                    string ghichu, bool trangthai)
        {
            using (HMSHospitalEntities add = new HMSHospitalEntities())
            {
                DichVu dichvu = new DichVu();
                dichvu.MaNhomDV = manhomdv;
                dichvu.MaDichVu = madichvu;
                dichvu.GiaDichVu = igiaDV;
                dichvu.TenDichVu = tendichvu;
                dichvu.GhiChu = ghichu;
                dichvu.TrangThai = trangthai;

                add.AddToDichVus(dichvu);
                add.SaveChanges();
            }
        }

        // chỉnh sửa dịch vụ
        public static void CapNhatDichvu(string manhomdv, string madichvu, string tendichvu,int iGiaDV, string ghichu, bool trangthai)
        {
            using (HMSHospitalEntities edit = new HMSHospitalEntities())
            {
                var dvu = (from chinhsua in edit.DichVus
                                where chinhsua.MaDichVu == madichvu
                                select chinhsua).First();
                dvu.MaNhomDV = manhomdv;
                dvu.TenDichVu = tendichvu;
                dvu.GiaDichVu = iGiaDV;
                dvu.GhiChu = ghichu;
                dvu.TrangThai = trangthai;
                edit.SaveChanges();
            }
        }
    }
}
